﻿@{
    ViewBag.Title = "固定资产仓库维护";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section Scripts{
    <script type="text/javascript">
        window.ondragstart = function () { window.event.returnValue = false; }
        window.oncontextmenu = function () { window.event.returnValue = false; }
        window.onselectstart = function () { event.returnValue = false; }
        var ParentCode; //父级节点编码
        var ParentName; //父级节点名称
        var TargetCode;  //目标节点编码
        var TargetName;  //目标节点名称
        $(document).ready(function () {
            initTree(); //初始化固定资产仓库树
            VerifyPermission(); //初始化权限验证
            $.setDivOnly("#TableForm");
        });
        $(window).resize(function () {
            $.setDivOnly("#TableForm");
        });

        //初始化固定资产类别树
        function initTree() {
            $('#StorageTree').tree({
                url: '@Url.Content("~/FixedAssets/FixedAssetsStorage/GetAllAssetsStorageTree")',
                method: 'POST',
                animate: true,
                lines: true,
                onContextMenu: function (e, node) {
                    e.preventDefault();
                    // 查找节点
                    $('#StorageTree').tree('select', node.target);
                    var pnode = $('#StorageTree').tree('getParent', node.target);
                    if (pnode != null) {  //如果有父节点
                        ParentCode = pnode.id;
                        ParentName = pnode.text;
                        TargetCode = node.id;
                        TargetName = node.text;
                        //// 显示快捷菜单
                        //$('#menu').menu('show', {
                        //    left: e.pageX,
                        //    top: e.pageY
                        //});
                    } else {
                        ParentCode = -1;
                        ParentName = "无";
                        TargetCode = node.id;
                        TargetName = node.text;
                    }

                    // 显示快捷菜单
                    $('#menu').menu('show', {
                        left: e.pageX,
                        top: e.pageY
                    });
                    //console.log(ParentCode);
                    //console.log(ParentName);
                    //console.log(TargetCode);
                    //console.log(TargetName);

                },
                formatter: function (node) {
                    if (node.attributes.IsActive == false) {
                        return '<span style="color:red">' + node.text + '[已禁用]</span>';
                    } else {
                        return node.text;
                    }
                },
                //onLoadSuccess: function (node, data) {
                //    console.log(data);
                //}
            });
        }

        //添加平级仓库
        function AddStroageLevel() {
            $.GID("btnadd").style.display = "block";
            $.GID("btnedit").style.display = "none";
            $('#ParentName').textbox('setText', ParentName);
            $('#ParentID').val(ParentCode)
            $('#Stroage').textbox('clear');
            $('#StroageEdit').dialog('open');
        }
        //添加下级仓库
        function AddStroageLowerLevel() {
            $.GID("btnadd").style.display = "block";
            $.GID("btnedit").style.display = "none";
            $('#ParentName').textbox('setText', TargetName);
            $('#ParentID').val(TargetCode);
            $('#Stroage').textbox('clear');
            $('#StroageEdit').dialog('open');
        }
        //修改
        function EditStroageInfo() {
            $.GID("btnadd").style.display = "none";
            $.GID("btnedit").style.display = "block";
            $('#ParentName').textbox('setText', ParentName);
            $('#StroageID').val(TargetCode);
            $('#Stroage').textbox('setText', TargetName);
            $('#StroageEdit').dialog('open');
        }
        //确认新增
        function submitAddForm() {
            var isValid = $("#StroageEdit").form("validate");
            if (isValid) {
                $('#btnadd').linkbutton('disable')
                $.ajax({
                    type: 'POST',
                    url: '@Url.Content("~/FixedAssets/FixedAssetsStorage/AddAssetsStorage")',
                    data:
                        {
                            PID: $('#ParentID').val(),
                            StroageName: $('#Stroage').textbox('getText')
                        },
                    dataType: "json",
                    success: function (jsData) {
                        $.handleJsonResult(jsData, function () {
                            initTree()
                            $('#StroageEdit').window('close');
                            $('#btnadd').linkbutton('enable'); //add 2019-09-18 启用按钮
                        }, function () {
                            $('#btnadd').linkbutton('enable');
                        });
                    }
                });
            }
        }
        //确认修改
        function submitEditForm() {
            $('#btnedit').linkbutton('disable')
            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/FixedAssets/FixedAssetsStorage/EditAssetsStorage")',
                data:
                    {
                        SID: $('#StroageID').val(),
                        StroageName: $('#Stroage').textbox('getText')
                    },
                dataType: "json",
                success: function (jsData) {
                    $.handleJsonResult(jsData, function () {
                        initTree()
                        $('#StroageEdit').window('close');
                        $('#btnedit').linkbutton('enable');//add 2019-09-18 启用按钮
                    }, function () {
                        $('#btnedit').linkbutton('enable');
                    });
                }
            });
        }
        //禁用该物资仓库
        function DisableAssetsStorage() {
            $.messager.confirm('提示确认', '确认将[仓库：【' + TargetName + '】禁用吗？', function (r) {
                if (r) {
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Content("~/FixedAssets/FixedAssetsStorage/DisableAssetsStorage")',
                        data:
                            {
                                SID: TargetCode
                            },
                        dataType: "json",
                        success: function (jsData) {
                            $.handleJsonResult(jsData, function () {
                                initTree();
                            });
                        }
                    });
                }
            });
        }
        //启用该物资仓库
        function EnableAssetsStorage() {
            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/FixedAssets/FixedAssetsStorage/EnableAssetsStorage")',
                data:
                    {
                        SID: TargetCode
                    },
                dataType: "json",
                success: function (jsData) {
                    $.handleJsonResult(jsData, function () {
                        initTree();
                    });
                }
            });
        }

        //函数：验证新增修改/启禁用分类权限
        function VerifyPermission() {
            //若最大统计权限为All
            if ('@ViewData["em"]' == 'ALL') {
                //判断有无新增修改分类权限
                if ('@ViewData["RolePermissionInsert"]' == "Insert") {  
                    $(".permissionInsert").show(); //右键菜单 添加修改仓库按钮显隐

                } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                    $(".permissionInsert").hide();
                }
                //判断有无启禁用分类权限
                if ('@ViewData["RolePermissionDelete"]' == "Delete") {
                    $(".permissionDelete").show(); //右键菜单 启/禁用仓库按钮显隐
                    
                } else if ('@ViewData["RolePermissionDelete"]' != "Delete") {
                    $(".permissionDelete").hide();
                }
                //end
            } else if ('@ViewData["em"]' == 'CENTER') { //最大统计权限为中心

                if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                    $(".permissionInsert").show();


                } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                    $(".permissionInsert").hide();

                }
                if ('@ViewData["RolePermissionDelete"]' == "Delete") {
                    $(".permissionDelete").show();
                  
                } else if ('@ViewData["RolePermissionDelete"]' != "Delete") {

                    $(".permissionDelete").hide();
                }
                //end

            } else if ('@ViewData["em"]' == 'STATION' || '@ViewData["em"]' == 'SELF') { //最大统计权限为分站或自己
                $("#menu").menu("destroy");//销毁右键菜单
            }
        }


    </script>
}
<div id="TableForm" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'固定资产仓库管理',iconCls:'icon-custom-cGoodClass'">
        <ul id="StorageTree"></ul>
        <div id="menu" class="easyui-menu" style="width:150px;">
            <div data-options="iconCls:'icon-custom-cGoodClass'" onclick="AddStroageLevel()" class="permissionInsert">添加平级仓库</div>
            <div data-options="iconCls:'icon-add'" onclick="AddStroageLowerLevel()" class="permissionInsert">添加下级仓库</div>
            <!--menusep 分割线-->
            <div class="menu-sep permissionInsert"></div>
            <div data-options="iconCls:'icon-edit'" onclick="EditStroageInfo()" class="permissionInsert">修改仓库信息</div>
            <div class="menu-sep permissionInsert"></div>
            <div data-options="iconCls:'icon-custom-cJinYong'" onclick="DisableAssetsStorage()" class="permissionDelete"><span style="color:red">禁用</span>该仓库</div>
            <div class="menu-sep permissionDelete"></div>
            <div data-options="iconCls:'icon-custom-cQiYong'" onclick="EnableAssetsStorage()" class="permissionDelete"><span style="color:darkgreen">启用</span>该仓库</div>
        </div>
    </div>
</div>
<!--固定资产分类维护弹层-->
<div id="StroageEdit" class="easyui-dialog" title="固定资产仓库维护" data-options="modal:true,collapsible:false,minimizable:false,maximizable:false,closed:true,resizable:false,iconCls:'icon-custom-cGoodClass'" style="width:300px;height:155px;padding:0px;">
    <div data-options="region:'center'" style="overflow: hidden">
        <table style="width:99%">
            <tr style="height:40px">
                <td>上级仓库：</td>
                <td>
                    <input id="ParentName" class="easyui-textbox" style="width:160px" data-options="readonly:true" />
                    <input id="ParentID" type="hidden" />
                </td>
            </tr>
            <tr style="height:40px">
                <td>仓库名称：</td>
                <td>
                    <input id="Stroage" class="easyui-textbox" style="width:160px" data-options="required:true" />
                    <input id="StroageID" type="hidden" />
                </td>
            </tr>
            <tr style="height:30px">
                <td colspan="2">
                    <a href="javascript:void(0)" id="btnedit" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="submitEditForm();">确认修改</a>
                    <a href="javascript:void(0)" id="btnadd" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="submitAddForm();">确认新增</a>
                </td>
            </tr>
        </table>
    </div>
</div>

<style>
    .tree-node-selected {
        background: #ffe48d;
        color: #000000;
    }

    .menu-active {
        border-color: #b7d2ff;
        color: #000;
        background: #eaf2ff;
    }
</style>

